package cn.smb.service;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.SqlSession;

import cn.smb.dao.UserMapper;
import cn.smb.entity.*;
import cn.smb.util.MyBatisUtil;

public class UserService {
	public static UserService SERVICE = new UserService();

	public Page<User> findAll(String username, Long roleId, int pageNo) {
		SqlSession s = MyBatisUtil.getSession();
		UserMapper userMapper = s.getMapper(UserMapper.class);

		List<User> list = userMapper.findAll(username, roleId, pageNo,
				Page.PAGESIZE);
		int total = userMapper.count(username, roleId);
		Page<User> p = new Page<User>(list, pageNo, total);
		return p;
	}

	public int deleteM(Long[] ids) {
		SqlSession s = MyBatisUtil.getSession();
		try {
			UserMapper userMapper = s.getMapper(UserMapper.class);
			return userMapper.deleteM(ids);
		} finally {
			s.commit();
			MyBatisUtil.close(s);
		}
	}
}
